// promise  封装ajax
function ajax(url) {
    new Promise(function (resolve, reject) {
        var xhr = new XMLHttpRequest()
        xhr.open('GET', url)
        xhr.responseText= 'json'
        xhr.onload = function (p) {
            if(this.status ===200) {
                resolve(this.response)
            } else {
                reject(new Error(this.responseText))
            }
        }
        xhr.send();
    })
}

ajax('/users.json').then(function (res) {
    console.log(res)
},function (error) {
    console.log(error)
})